package com.xmu.edu.tisp.service.taskprocess;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.xmu.edu.tisp.dao.Service;
import com.xmu.edu.tisp.dao.TISP_dbHelper;

public class CR_TASK_TYPE_service implements Service{
	
	public static final String TABLE_NAME = "CR_TASK_TYPE";
	public static final String PRIMARY_KEY="TASK_TYPE_ID";
	
	
	private SQLiteDatabase myDB;
	private SQLiteOpenHelper dbHelper;


	public CR_TASK_TYPE_service(Context cxt)
	{
		dbHelper=new TISP_dbHelper(cxt, "TISP");
	}
	public SQLiteDatabase getdb()
	{
		if(myDB==null)
		{
			myDB=dbHelper.getWritableDatabase();
			return myDB;
		}
		return myDB;
	}
	
	@Override
	public void g_updata(ContentValues values) {
		getdb().update(TABLE_NAME, values, PRIMARY_KEY+"=?", new String[]{(String) values.get(PRIMARY_KEY)});
	}

	@Override
	public void g_insert(ContentValues values) {
		getdb().insert(TABLE_NAME, null, values);
		
	}

	@Override
	public void g_delete(String[] id) {
		getdb().delete(TABLE_NAME, PRIMARY_KEY+"=?", id);
		
	}


	@Override
	public List<String> g_getIDs() {
		Cursor c=getdb().query(TABLE_NAME, new String[]{PRIMARY_KEY},null, null, null, null, null);
		List<String> result=new ArrayList<String>();
		while(c.moveToNext())
		{
			String id=c.getString(c.getColumnIndex(PRIMARY_KEY));
			result.add(id);
		}
		return result;
	}
	
	public Cursor getTasksTypeByID(String[] id)
	{
		Cursor c=getdb().query(TABLE_NAME, null,PRIMARY_KEY+"=?", id, null, null, null);
		
		return c;
	}
}
